/*
 * PswTable.java
 *
 * Created on 2009年2月13日, 下午6:13
 */

package main.view;

import main.model.PswTable_Model;
import main.model.UserPsw_Model;
import medium.MsgSender;

/**
 *
 * @author  I'm kevin
 */
public class PswTable extends javax.swing.JFrame {
    private static PswTable pt;
    private String id;
    /** Creates new form PswTable */
    
    public PswTable() {
        initComponents();
        this.setLocationRelativeTo(null);
    }
    
    public static PswTable getInstance(String id){
        if(pt==null){
            pt = new PswTable();
            pt.setVisible(true);
            pt.id=id;
        }
        else
        {
            pt.id=id;
            pt.psw_PF.setText("");
            pt.setVisible(true);
        }
        return pt;
    }
    
    public PswTable_Model getPswTable_Model(){
        PswTable_Model ptm = new PswTable_Model();
        ptm.setOk(ok_Bo);
        ptm.setCancel(cancel_Bo);
        return ptm;
    }
    
    public UserPsw_Model getUserPsw_Model(){
        UserPsw_Model upm = new UserPsw_Model();
        upm.setPsw(String.valueOf(this.psw_PF.getPassword()));
//        System.out.println();
        return upm;
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        ok_Bo = new javax.swing.JButton();
        psw_La = new javax.swing.JLabel();
        psw_PF = new javax.swing.JPasswordField();
        cancel_Bo = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("ISC_System");
        setResizable(false);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Enter Private Code", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 0, 18))); // NOI18N

        ok_Bo.setFont(new java.awt.Font("Arial", 0, 12));
        ok_Bo.setText("OK");
        ok_Bo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ok_BoActionPerformed(evt);
            }
        });

        psw_La.setFont(new java.awt.Font("Arial", 1, 12));
        psw_La.setText("Password:");

        psw_PF.setEchoChar('*');

        cancel_Bo.setFont(new java.awt.Font("Arial", 0, 12));
        cancel_Bo.setText("Cancel");
        cancel_Bo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancel_BoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(37, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(ok_Bo, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(psw_La, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(psw_PF, javax.swing.GroupLayout.PREFERRED_SIZE, 186, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cancel_Bo)
                .addGap(23, 23, 23))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGap(36, 36, 36)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(psw_La)
                    .addComponent(psw_PF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 39, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ok_Bo)
                    .addComponent(cancel_Bo))
                .addGap(47, 47, 47))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void ok_BoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ok_BoActionPerformed
            MsgSender.getInstance().toVerify(id, String.valueOf(this.psw_PF.getPassword()));
            this.setVisible(false);
    }//GEN-LAST:event_ok_BoActionPerformed

    private void cancel_BoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancel_BoActionPerformed
            this.setVisible(false);
            MainTable.getInstance().getButtonModel().getCardID().setText("");
    }//GEN-LAST:event_cancel_BoActionPerformed
    
    /**
     * @param args the command line arguments
     */

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new PswTable().setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cancel_Bo;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JButton ok_Bo;
    private javax.swing.JLabel psw_La;
    private javax.swing.JPasswordField psw_PF;
    // End of variables declaration//GEN-END:variables
    
}
